<template>
  <div class="tenantMenu_main main_container">
    <div class="main_header">
      <div class="padding_container">
        <div class="left"><Breadcrumb /></div>
        <div class="right">
          <HeaderOperation :parent="this" />
        </div>
      </div>
    </div>
    <div v-loading="loading" class="main_main">
      <SearchBar :parent="this" />
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          stripe
          border
          :height="tableHeight"
          row-key="id"
          :cell-style="cellStyle"
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
        >
          <Column v-for="(column,index) in tableColumns" :key="index" :prop="column.prop" :is-show="column.isShow" :label="column.label" :sortable="column.sortable" :width="column.width" />
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>

  </div>
</template>

<script>
import { list as getCompany } from '@/api/superManage/tenantManage'
import { list } from '@/api/superManage/systemMonitoring/customerFollow'
import { mapGetters } from 'vuex'
export default {
  name: 'Index',
  computed: {
    ...mapGetters([
      'companyId'
    ])
  },
  data() {
    return {
      loading: false,
      pageId: '客户跟进', // 页面唯一标识
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc'
      },
      total: 1, // 数据一共有多少条
      mainId: 'id', // 表格行ID
      tableHeight: '0', // 表格高度
      tableData: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      companyOptions: [],
      defaultTableColumns: [// 表格常规字段（初始值）
        { prop: 'statusName', label: '状态' },
        { prop: 'companyName', label: '公司名称' },
        { prop: 'userName', label: '最新登录账号' },
        { prop: 'realName', label: '最新登录人员' },
        { prop: 'loginTime', label: '最新登录时间' },
        { prop: 'businessTypeName', label: '操作类型' },
        { prop: 'title', label: '操作内容' },
        { prop: 'realName2', label: '操作人员' },
        { prop: 'operTime', label: '操作时间' }
      ],
      defaultSearchColumns: [// 搜索区常规字段（初始值）
        // { prop: 'companyName', label: '公司名称', type: 'input' },
        { prop: 'customerId', label: '公司名称', type: 'select', optionsName: 'companyOptions' },
        { prop: 'searchTime', label: '统计时间', type: 'time' }
      ],
      operationData: [ // 右上角的操作按钮
        { label: '页面配置', perm: '' }
      ]

    }
  },
  created() {
    getCompany().then(res => {
      // this.companyOptions = res.data
      // console.log(this.companyOptions)

      const cacheData = []
      res.data.forEach(item => {
        cacheData.push({
          value: item.id,
          label: item.name
        })
      })
      this.companyOptions = cacheData
    })
    this.pageData.searchTime = [this.$moment(new Date()).subtract(1, 'weeks').format('YYYY-MM-DD') + ' 00:00',
      this.$moment(new Date()).format('YYYY-MM-DD') + ' 23:59']
  },
  mounted() {
    this.$nextTick(() => {
      this.tableHeight = this.$refs.table_container.offsetHeight
    })
  },
  methods: {
    cellStyle({ row, column }) {
      if (column.property == 'statusName') {
        if (row.statusName == '使用中') {
          return {
            color: '#19BE6B'
          }
        } else {
          return {
            color: '#F56C6C'
          }
        }
      }
    },
    getList() {
      this.loading = true
      list({ ...this.pageData }).then(res => {
        this.tableData = res.data
        this.total = res.total
        this.$nextTick(() => {
          this.setSelectRow(this)// 设置行选中
        })
      }).finally(() => {
        this.loading = false
      })
    },
    refresh() {
      this.pageData.pageNum = 1
      this.getList()
    }
  }
}
</script>

  <style lang="less" scoped>
  </style>
